<% admin_breadcrumb(link_to Spree.t(:stock), spree.admin_stock_items_path) %>
<% admin_breadcrumb(link_to plural_resource_name(Spree::StockTransfer), spree.admin_stock_transfers_path) %>
<% admin_breadcrumb(@stock_transfer.number) %>


<% content_for :page_actions do %>
  <li>
  </li>
  <li>
    <%= button_link_to Spree.t(:ready_to_ship),
      finalize_admin_stock_transfer_path(@stock_transfer),
      method: 'put',
      data: { confirm: Spree.t('finalize_stock_transfer.confirm') }
    %>
  </li>
<% end %>

<%= form_for [:admin, @stock_transfer] do |f| %>
  <fieldset class="no-border-top">
    <div>
      <label><%= Spree.t(:created_by) %></label>
      <p><%= @stock_transfer.created_by.email %></p>
    </div>
    <%= f.field_container :description do %>
      <%= f.label :description %>
      <%= f.text_field :description, value: @stock_transfer.description, maxlength: 255, size: 0, class: 'fullwidth' %>
      <%= f.error_message_on :description %>
    <% end %>
    <%= f.field_container :destination_location do %>
      <%= f.label :destination_location_id %>
      <%= f.select :destination_location_id, options_from_collection_for_select(@destination_stock_locations, :id, :name, @stock_transfer.destination_location_id), {include_blank: true}, {class: 'select2 fullwidth', "data-placeholder" => Spree.t(:select_a_stock_location)} %>
      <%= f.error_message_on :destination_location %>
    <% end %>
    <div class="filter-actions actions" data-hook="buttons">
      <%= button Spree.t('actions.save') %>
    </div>
  </fieldset>
<% end %>

<fieldset id='stock-transfer-edit-variants'>
  <legend align="center"><%= Spree.t(:variant_to_add) %></legend>
  <div data-hook="transfer_item_selection">
    <%= hidden_field_tag :stock_transfer_number, @stock_transfer.number %>
    <%= hidden_field_tag :variant_display_attributes, @variant_display_attributes.to_json %>
    <%= text_field_tag :transfer_item_variant_id, "", :class => "variant_autocomplete fullwidth" %>
  </div>
</fieldset>

<fieldset id='stock-transfer-transfer-items'>
  <legend align="center"><%= Spree.t(:added) %></legend>
  <%= render partial: 'transfer_item_table', locals: { transfer_items: @stock_transfer.transfer_items, show_expected: true, show_received: false, show_actions: true } %>
</fieldset>
